/*
import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from "unplugin-vue-components/resolvers";


// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    AutoImport({
      resolvers:[ElementPlusResolver()],
    }),
    Components({
      resolvers: [
        //配置ElementPlus采用sass样式配置主题色
        ElementPlusResolver({importStyle:'sass'})
      ]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  css:{
    preprocessorsOptions: {
      scss:{
        additionalData: `
        @use "@/styles/var.scss" as *;
        @use "@/styles/common.scss" as *;
        `
      }
    }
  },

  server: {
    allowedHosts: ["hz14531ge93.vicp.fun","0.0.0.0:5173","wf8b8c26.natappfree.cc"],
    host: '0.0.0.0',
    port: 5173 // 可以根据需要修改端口号
  },
 /!* server: {
    host: '0.0.0.0',
    port: 5173 // 可以根据需要修改端口号
  }*!/
})
*/

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
      imports: ['vue', 'vue-router'],
      dts: 'src/auto-imports.d.ts'
    }),
    Components({
      resolvers: [
        // 配置 ElementPlus 采用 sass 样式配置主题色
        ElementPlusResolver({ importStyle: 'sass' })
      ],
      dts: 'src/components.d.ts'
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  css: {
    preprocessorsOptions: {
      scss: {
        additionalData: `
        @use "@/styles/var.scss" as *;
        @use "@/styles/common.scss" as *;
        `
      }
    }
  },
  server: {
    allowedHosts: ["192.168.1.245", "haike.nat300.top","localhost"],
    host: '0.0.0.0',
    port: 5173,
    // 配置代理解决跨域问题（如果需要）
    proxy: {
      '/apis': {
        target: 'http://localhost:8080', // 后端服务地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
      '/files': {
        target: 'http://localhost:8081', // 后端服务地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/files/, '')
      },
      '/images': {
        target: 'http://localhost:9000', // 后端服务地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/images/, '')
      }
    }
  },
  // 生产环境构建配置
  build: {
    outDir: 'dist',
    assetsDir: 'static',
    sourcemap: false,
    rollupOptions: {
      output: {
        // 拆分大块 JavaScript 文件
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    }
  }
})
